/*
 * Copyright (C) 2006-2012 TongYan Corporation
 * All rights reserved.
 *
 * @brief info:
 *
 * @author: 王哲成 - wangzhecheng@yeah.net
 * @date: 2021.05.25
 * @last modified: 2021-05-25 12:57
 *
 */

#include "../include/NewtonMethod.hpp"

bool NewtonMethod::updateSearchPoint(const ParamSet &param_set,
                                     Candidate &candidate) const {
  // 计算梯度矩阵Jx(负方向)
  Vector Jx = m_ptrTarFunc->gradientVector(candidate.first, param_set.dx());
  if (Jx.squaredNorm() < m_dEpsilon * m_dEpsilon)
    return true;
  // 计算海塞矩阵Hx
  Matrix Hx = m_ptrTarFunc->HessianMatrix(candidate.first, param_set.dx());

  // dx = -H(x)^-1*J(x)
  candidate.first -= Hx.colPivHouseholderQr().solve(Jx);

  return false;
}
